= gitlab_ui_form_for cluster, url: update_cluster_url_path, html: { class: 'js-provider-details gl-show-field-errors', role: 'form' },
  as: :cluster do |field|
  .form-group
    = field.label :name, s_('ClusterIntegration|Kubernetes cluster name'), class: 'label-bold required'
    .input-group.gl-field-error-anchor
      = field.text_field :name, class: 'form-control js-select-on-focus cluster-name', required: true,
        title: s_('ClusterIntegration|Cluster name is required.'),
        readonly: cluster.read_only_kubernetes_platform_fields?
      - if cluster.read_only_kubernetes_platform_fields?
        .input-group-append
          = clipboard_button(text: cluster.name, title: s_('ClusterIntegration|Copy Kubernetes cluster name'), variant: :default, category: :primary, size: :medium)

  = field.fields_for :platform_kubernetes, platform do |platform_field|
    .form-group
      = platform_field.label :api_url, s_('ClusterIntegration|API URL'), class: 'label-bold required'
      .input-group.gl-field-error-anchor
        = platform_field.text_field :api_url, class: 'form-control js-select-on-focus', required: true,
          title: s_('ClusterIntegration|API URL should be a valid http/https url.'),
          readonly: cluster.read_only_kubernetes_platform_fields?
        - if cluster.read_only_kubernetes_platform_fields?
          .input-group-append
            = clipboard_button(text: platform.api_url, title: s_('ClusterIntegration|Copy API URL'), variant: :default, category: :primary, size: :medium)

    .form-group
      = platform_field.label :ca_cert, s_('ClusterIntegration|CA Certificate'), class: 'label-bold'
      .input-group.gl-field-error-anchor.markdown-code-block
        = platform_field.text_area :ca_cert, class: '!gl-rounded-tr-base !gl-rounded-br-base form-control js-select-on-focus', rows: '10',
          readonly: cluster.read_only_kubernetes_platform_fields?,
          placeholder: s_('ClusterIntegration|Certificate Authority bundle (PEM format)')
        - if cluster.read_only_kubernetes_platform_fields?
          %copy-code
            = clipboard_button(text: platform.ca_cert, title: s_('ClusterIntegration|Copy CA Certificate'), variant: :default, category: :primary, size: :medium, class: 'copy-code')

    .form-group
      = platform_field.label :token, s_('ClusterIntegration|Enter new Service Token'), class: 'label-bold required'
      .input-group.gl-field-error-anchor
        = platform_field.password_field :token, type: 'password', class: 'form-control js-select-on-focus js-cluster-token',
          readonly: cluster.read_only_kubernetes_platform_fields?, autocomplete: 'new-password'

    .form-group
      .form-check
        = platform_field.check_box :authorization_type, { disabled: true, inline: true, class: 'form-check-input' }, 'rbac', 'abac'
        = platform_field.label :authorization_type, s_('ClusterIntegration|RBAC-enabled cluster'), class: 'form-check-label label-bold'
      .form-text.gl-text-subtle
        = s_('ClusterIntegration|Enable this setting if using role-based access control (RBAC).')
        = s_('ClusterIntegration|This option will allow you to install applications on RBAC clusters.')

    .form-group
      .form-check
        = field.check_box :managed, { class: 'js-gl-managed form-check-input' }
        = field.label :managed, s_('ClusterIntegration|GitLab-managed cluster'), class: 'form-check-label label-bold'
      .form-text.gl-text-subtle
        = s_('ClusterIntegration|Allow GitLab to manage namespaces and service accounts for this cluster.')
        = link_to _('More information'), help_page_path('user/project/clusters/gitlab_managed_clusters.md'), target: '_blank', rel: 'noopener noreferrer'

    .form-group
      .form-check
        = field.check_box :namespace_per_environment, { class: 'form-check-input' }
        = field.label :namespace_per_environment, s_('ClusterIntegration|Namespace per environment'), class: 'form-check-label label-bold'
      .form-text.gl-text-subtle
        = s_('ClusterIntegration|Deploy each environment to its own namespace. Otherwise, environments within a project share a project-wide namespace. Note that anyone who can trigger a deployment of a namespace can read its secrets. If modified, existing environments will use their current namespaces until the cluster cache is cleared.')
        = link_to _('More information'), help_page_path('user/project/clusters/deploy_to_cluster.md', anchor: 'custom-namespace'), target: '_blank', rel: 'noopener noreferrer'

    - if cluster.allow_user_defined_namespace?
      = render('clusters/clusters/namespace', platform_field: platform_field, field: field)

  .form-group
    = field.submit s_('ClusterIntegration|Save changes'), pajamas_button: true
